package com.study.java8;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description Java8
 * @Author hgg
 * @Date 2019/12/12 13:43
 * @Version 1.0
 */
public class Java8 {

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        // 获取对应的平方数
        List<Integer> squaresList = numbers.stream().map( i -> i*i).distinct().collect(Collectors.toList());
        squaresList.forEach(theNum -> System.out.println(theNum+"||"));
//        System.out.println(squaresList->);


        List<User> list = new ArrayList<>();
        list.add(new User(1,12,"java"));
        list.add(new User(2,13, "python"));
        list.add(new User(3,14, "js"));
        list.add(new User(4,15, "scala"));
        list.add(new User(5,16, "ruby"));
        list.add(new User(6,17, "c"));

        Collections.sort(list, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                return o2.getAge() - o1.getAge();
            }
        });

        for(User user : list){
            System.out.println(user);
        }

        list.sort((o1, o2) -> o1.getAge() - o2.getAge());

        System.out.println("-------------------——————————————");
        for(User user : list){
            System.out.println(user);
        }
    }
}
